package com.tyk.demo.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class SwaggerConfig {
    /**
     * API接口包路径
     */
    @Value("${swagger.base-package}")
    private String basePackage;

    /**
     * API页面标题
     */
    @Value("${swagger.title}")
    private String title;

    /**
     * API描述
     */
    @Value("${swagger.description}")
    private String description;

    /**
     * 服务条款地址
     */
    @Value("${swagger.terms-of-service-url}")
    private String termsOfServiceUrl;

    /**
     * 版本号
     */
    @Value("${swagger.version}")
    private String version;

    /**
     * 联系人
     */
//    @Value("${swagger.contact}")
//    private Contact contact;

    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage(basePackage))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title(title)
                .description(description)
                .termsOfServiceUrl(termsOfServiceUrl)
                .version(version)
//                .contact(contact)
                .build();
    }
}
